package bin_tree.oj;

import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

public class Num144 {
    List<Integer> ret = new LinkedList<>();
    public List<Integer> preorderTraversal(TreeNode root) {
        if(root == null){
            return ret;
        }
        Stack<TreeNode> stack = new Stack<>();
        stack.push(root);
        while (!stack.isEmpty()){
            TreeNode node = stack.pop();
            ret.add(node.val);
            if (root.right != null){
                stack.push(root.right);
            }
            if (root.left != null){
                stack.push(root.left);
            }
        }
        return ret;
    }
}
